<?php

function spinRoulette($odds)
{
	$hitWedge = -1;
	$wedgeMin = 0;
	$wedgeMax = 0;
	$shoot = rand( 1, 100 );
	
	for( $ind = 0; $ind < count($odds); $ind++ )
	{
		$wedgeMax = $wedgeMin + $odds[$ind];
		
		if( ($shoot > $wedgeMin) && ($shoot <= $wedgeMax) )
		{
			$hitWedge = $ind;
			break;
		}
		
		$wedgeMin = $wedgeMax;
	}
	
	return $hitWedge;
}

// start execution
$odds = array( 40, 40, 20 );
for( $ind = 0; $ind < 100; $ind++ )
{
	$hitWedge = spinRoulette($odds);
	echo "hitWedge: $hitWedge <br>";
}
?>

